<!--
 * @description  :铁路运输档案维护
 * @descriptionDetail:铁路运输档案维护
 * @copyright    : 浙江烟草
 * @author       : dw
 * @create       : 2022-10-09 22:21:21
-->
<template>
  <view class="page">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar title="铁路运输档案维护"></theme-navbar>
    <!-- #endif -->
    <view class="content content-bg ifn-content" style="background-color: white">
      <u-form
        class="u-form-m"
        :label-style="labelStyle"
        :model="baseInfo"
        :error-type="['border-bottom', 'message',]"
        label-width="auto"
        label-position="top"
        ref="uForm"
      >
        <u-form-item label="班次名称" prop="serviceName" :required="true">
          <u-input v-model="baseInfo.serviceName" :disabled="isDisabled" placeholder="请输入"></u-input>
        </u-form-item>
        <u-form-item label="登记单位" :required="true">
          <u-input :disabled="true" placeholder="请选择" v-model="baseInfo.orgName"></u-input>
        </u-form-item>
        <u-form-item label="始发时间">
          <u-input
            v-model="baseInfo.startTime" placeholder="请选择" :disabled="true" :custom-style="pointerStyle"
            @click="dateChange"
          ></u-input>
        </u-form-item>
        <u-form-item label="始发站">
          <u-input v-model="baseInfo.startStation" placeholder="请输入"></u-input>
        </u-form-item>
        <u-form-item label="途径站点">
          <u-input v-model="baseInfo.pathWayStation" placeholder="请输入"></u-input>
        </u-form-item>
        <u-form-item label="终点">
          <u-input v-model="baseInfo.endStation" placeholder="请输入"></u-input>
        </u-form-item>
        <u-form-item label="案发站">
          <u-input v-model="baseInfo.caseStation" placeholder="请输入"></u-input>
        </u-form-item>
        <u-form-item label="时间班次">
          <u-input v-model="baseInfo.service" placeholder="请输入"></u-input>
        </u-form-item>
        <u-form-item label="是否伪装" prop="pretend">
          <dic-input
            :keyWord="$u.dic.DIC_KEYS.S_SYS_YES_NO"
            :dicCode="baseInfo.pretend"
            :border="false"
            type="select"
            :select-open="dicSelectOpen('pretend',$u.dic.DIC_KEYS.S_SYS_YES_NO)"
            placeholder="请选择"
            :disabled="true"
            v-model="baseInfo.pretendStr"
            @changeInputModelData="(name)=>{$set(baseInfo, 'pretendStr', name)}"
            @click="showDic($u.dic.DIC_KEYS.S_SYS_YES_NO,baseInfo.pretend,'pretend')"
          />
        </u-form-item>
        <u-form-item label="所属铁路局">
          <u-input v-model="baseInfo.trainName" placeholder="请输入"></u-input>
        </u-form-item>
      </u-form>
    </view>
    <view class="u-form">
      <u-gap :height="$theme.cm_section_top_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
      <fsection :title="title.images" :customStyle="customStyle"></fsection>
    </view>
    <view class="u-form-m pl-10">
      <m-upload
        :uploadParam="fileUploadParam" upApiUrl="uploadBase64ForApp" :fileList="fileList"
        @on-list-change="changeUpload"
      ></m-upload>
    </view>
    <view class="submit-btns bottom-btns">
      <u-button class="del" type="primary" @click="submit">
        保&nbsp;&nbsp;&nbsp;&nbsp;存
      </u-button>
    </view>
    <!-- 组织机构选择 -->
    <u-popup mode="bottom" height="80%" v-model="orgSelectShow">
      <org-select
        :cleanParentOrg="true" :isHybrid="true" limitNodeType="all"
        treeType="zm-comp" @choose="handlerChooseOrg"
      ></org-select>
    </u-popup>
    <!-- 字典单选 -->
    <dic-choice
      :keyWord="dicKeyWords" :currentSelect="dicCurrentSelect" v-model="dicShow"
      @confirm="selectDicConfirm"
    ></dic-choice>
    <u-picker
      mode="time" :params="paramsTime" v-model="dateRange"
      @confirm="handlerSearchDate" @cancel="showTime = false"
    ></u-picker>
  </view>
</template>

<script>
import areaSelect from '@/components/area-select.vue';
import DicInput from '@/components/dic_input.vue';
import DicChoice from '@/components/dic_choice.vue';
import OrgSelect from '@/components/org-select.vue';
import intelligenceservice from '@/service/intelligence/intelligence.service';
import { uuid, } from '@/common/util.js';
import MUpload from '@/components/m-upload.vue';
import fsection from '@/components/form-section.vue';
export default {
  components: {
    OrgSelect,
    DicChoice,
    DicInput,
    MUpload,
    fsection,
  },
  data() {
    return {
      customStyle: {
        padding: '20rpx 32rpx',
      },
      fileUploadParam: {
        fiGroupCode: this.$FILE_GROUP_TYPE.k_transport_attr,
        bizId: '',
      },
      rules: {
        serviceName: [
          {
            required: true,
            message: '请输入班次名称',
            // 可以单个或者同时写两个触发验证方式
            trigger: ['change', 'blur',],
          },
        ],
      },
      baseInfo: {
        caseStation: '',
        endStation: '',
        historyUuid: '',
        menuCode: null,
        orgUuid: '',
        orgName: '',
        pathWayStation: '',
        service: '',
        serviceName: '',
        startStation: '',
        trainName: '',
      },
      labelStyle: {
        fontWeight: 400,
        color: this.$theme.u_main_color,
        fontSize: '.75rem',
      },
      iconstlye: {
        fontSize: '40rpx',
        color: this.$theme.u_type_primary,
      },
      title: {
        images: '图片信息',
        tag: '关联产品',
        connectMsg: '铁路运输档案维护',
      },
      from: 'add',
      orgSelectShow: false,
      nativeNameSelectShow: false,
      dicKeyWords: '',
      dicCurrentSelect: '',
      dicShow: false,
      fileList: [],
      user: this.$storage.get(this.$rp.common.USER),
      isDisabled: false,
      dateRange: false,
      // 模式
      paramsTime: {
        year: true,
        month: true,
        day: true,
        hour: true,
        minute: true,
        second: true,
      },
			// h5端部分浏览器input设置disabled后点击事件失效 2023-10-27 fsx start
			pointerStyle: {
			  marginRight: "5px",
				pointerEvents: "none !important"
			},
			// h5端部分浏览器input设置disabled后点击事件失效 2023-10-27 fsx end
    };
  },
  onLoad(opt) {
    this.from = opt.from;
    if (this.from === 'edit') {
      this.isDisabled = false;
      this.baseInfo = this.getRouteParam();
      this.fileUploadParam.bizId = this.baseInfo.uuid;
      let params = {
        bizId: this.baseInfo.uuid,
        group: this.$FILE_GROUP_TYPE.k_transport_attr,
        menuCode: null,
      };
      intelligenceservice.findFilesByBizIdAndGroup(params).then((res) => {
        if (res.success) {
          this.fileList = res.data;
        }
      });
    } else {
      this.baseInfo.uuid = uuid();
      this.fileUploadParam.bizId = this.baseInfo.uuid;
      if (this.user.orgLevel === 1) {
        this.baseInfo.orgName = this.user.provOrgName;
        this.baseInfo.orgUuid = this.user.provOrgUuid;
      } else {
        this.baseInfo.orgName = this.user.townOrgName;
        this.baseInfo.orgUuid = this.user.townOrgUuid;
      }
    }
  },
  onReady() {
    this.$refs.uForm.setRules(this.rules);
    this.getListViewTop();
  },
  mounted() {},
  methods: {
    getListViewTop() {
      this.$u.getRect('.case-search-lay').then((res) => {
        this.listViewTop = this.$u.sys().statusBarHeight + res.top + res.height + 'px';
      });
      this.$u.getRect('.submit-btns').then((res) => {
        this.bottomOffset = this.$u.sys().screenHeight - res.top + 'px';
      });
    },
    // 上传/删除图片事件
    changeUpload(list, key) {
      if (list.length > 0) {
        this.fileList = [...list,];
      } else {
        this.fileList = [];
      }
    },
    dateChange() {
      this.dateRange = true;
    },
    handlerSearchDate(e) {
      let time = e.year + '-' + e.month + '-' + e.day + ' ' + e.hour + ':' + e.minute + ':' + e.second;
      this.baseInfo.startTime = time;
    },
    handlerChooseOrg(orgs) {
      this.baseInfo.orgUuid = orgs[0].id;
      this.baseInfo.orgName = orgs[0].name;
      this.orgSelectShow = false;
    },
    selectDicConfirm(e) {
      if (this.dicKeyWords == this.$u.dic.DIC_KEYS.S_SYS_YES_NO) {
        // 是否伪装
        this.baseInfo.pretendStr = e[0].label;
        this.baseInfo.pretend = e[0].extra.bcbCode;
      }
    },
    dicSelectOpen(type, keyWords) {
      if (type == this.dicType) {
        if (this.dicKeyWords == keyWords && this.dicShow) {
          return true;
        }
        return false;
      }
    },
    showDic(key, cur, type) {
      if (this.dicShow) return;
      this.dicKeyWords = key;
      this.dicCurrentSelect = cur;
      this.dicShow = true;
      this.dicType = type;
    },
    submit() {
      this.$refs.uForm.validate((valid) => {
        if (valid) {
          let params = this.baseInfo;
          this.$modal.showLoading('保存中...');
          intelligenceservice
            .savetrainInfoPage(params)
            .then((res) => {
              this.$modal.hideLoading();
              if (res.success) {
                this.baseInfo = res.data;
                this.backPrev({
                  paramKey: 'refresh',
                  param: true,
                });
              } else {
                this.$u.toast(res.msg);
              }
            })
            .catch((err) => {
              this.$modal.hideLoading();
              console.log(err);
              this.$u.toast('保存失败');
            });
        } else {
          console.log('验证失败');
        }
      });
    },
    close() {
      this.$u.route('pages/intelligence/intelligenceTransportList');
    },
  },
};
</script>

<style scoped lang="scss">
	@import './add.scss';
</style>
